package influxdb

import influx "github.com/influxdata/influxdb1-client/v2"

var (
	ConnInflux    influx.Client
	InfluxConfig  influxConfig
	PointsSubChan chan influx.BatchPoints
)

type influxConfig struct {
	Address  string `ini:"address"`
	Username string `ini:"username"`
	Password string `ini:"password"`
}

func InitInfluxData() (err error) {
	ConnInflux, err = influx.NewHTTPClient(influx.HTTPConfig{
		Addr:     InfluxConfig.Address,
		Username: InfluxConfig.Username,
		Password: InfluxConfig.Password,
	})

	PointsSubChan = make(chan influx.BatchPoints, 10)
	go writePoints()
	return err
}
